﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.DataFormats;

namespace Bank_database_system
{
    public partial class 支行信息b : UserControl
    {
        // 定义一个事件，用于通知父控件
        public event EventHandler ButtonBack;

        public 支行信息b()
        {
            InitializeComponent();
        }


        private void button8_Click(object sender, EventArgs e)
        {
            // 触发事件，通知父控件
            ButtonBack?.Invoke(this, EventArgs.Empty);
        }

        private void 支行信息b_Load(object sender, EventArgs e)
        {

        }

        private void textBox9_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            // textBox9 支行id
            // textBox1 名称
            // textBox10 地址
            // textBox2 电话号码
            // 获取支行id
            string branchId = string.IsNullOrEmpty(textBox9.Text) ? null : textBox9.Text;
            // 获取名称
            string name = string.IsNullOrEmpty(textBox1.Text) ? null : textBox1.Text;
            // 获取地址
            string address = string.IsNullOrEmpty(textBox10.Text) ? null : textBox10.Text;
            // 获取电话号码
            string phoneNumber = string.IsNullOrEmpty(textBox2.Text) ? null : textBox2.Text;
            if(branchId != null && name != null && address != null && phoneNumber != null ){
                FunctionsforITDepartment.UpdateBranch(branchId, name, address, phoneNumber);
                MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ButtonBack?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                MessageBox.Show("请检查信息填写是否完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }
    }
}
